const commentsModel = require('../model/commentsModel.js');
module.exports = {
  getCommentsByPage(req,res){
    let {pageIndex,pageSize} = req.body;
    commentsModel.getCommentsByPage(pageIndex,pageSize,(err,result)=>{
      let resObj = {};
      if(err) console.error(err);
      if(result.length > 0){
        resObj.code = 200;
        resObj.msg = '获取成功';
        resObj.data = result;
        commentsModel.getCommentsTotal((err,result)=>{
          if(err) console.error(err);
          if(result.length > 0){
            let total = result[0].total;
            resObj.maxPage = total;
          res.send(resObj);
          }
        });
      }else{
        resObj.code = 401;
        resObj.msg = '获取失败';
        res.send(resObj);
      };
 
    });
  }
  
};